home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / e / amigae33a.lha / E_v3.3a / Src.lha / Src / Tools / Useful / ecode.e < prev    next >
Text File  |  1995-10-09  |  5KB  |  208 lines

  1. OPT MODULE
  2.  
  3. MODULE 'exec/memory',
  4.        'hardware/custom'
  5.   
  6. -> Wraps an E function so it can still access globals, even from other tasks.
  7. EXPORT PROC eCode(func) IS setup(func,{start},{end}-{start})
  8.  
  9. -> Wraps an E function as above, but also preserves the non-scratch registers.
  10. EXPORT PROC eCodePreserve(func) IS setup(func,{pStart},{pEnd}-{pStart})
  11.  
  12. -> Wraps an E function for use with createTask()
  13. EXPORT PROC eCodeTask(func) IS eCode(func)
  14.  
  15. -> Wraps an E function for use as an ASL hook
  16. EXPORT PROC eCodeASLHook(func) IS setup(func,{aStart},{aEnd}-{aStart})
  17.  
  18. -> Wraps an E function for use as an CX custom function
  19. EXPORT PROC eCodeCxCustom(func) IS setup(func,{cStart},{cEnd}-{cStart})
  20.  
  21. -> Wraps an E function for use as a GEL collision function
  22. EXPORT PROC eCodeCollision(func) IS eCodeCxCustom(func)
  23.  
  24. -> Wraps an E function for use as an interrupt handler
  25. EXPORT PROC eCodeIntHandler(func) IS setup(func,{hStart},{hEnd}-{hStart})
  26.  
  27. -> Wraps an E function for use as an interrupt server
  28. EXPORT PROC eCodeIntServer(func) IS setup(func,{sStart},{sEnd}-{sStart})
  29.  
  30. -> Wraps an E function for use as a software interrupt
  31. EXPORT PROC eCodeSoftInt(func) IS setup(func,{iStart},{iEnd}-{iStart})
  32.  
  33. -> Wraps an E function as eCode(), but swaps the order of two args
  34. EXPORT PROC eCodeSwapArgs(func) IS setup(func,{oStart},{oEnd}-{oStart})
  35.  
  36. EXPORT PROC eCodeDispose(mem) IS IF mem THEN Dispose(mem-8) ELSE NIL
  37.  
  38. PROC setup(func, addr, len) HANDLE
  39.   DEF mem:PTR TO LONG, a4
  40.   mem:=NewM(len, MEMF_PUBLIC)
  41.   -> Fully relocatable code can be copied to another memory location
  42.   CopyMem(addr, mem, len)
  43.   mem[]++:=func
  44.   MOVE.L A4, a4
  45.   mem[]++:=a4
  46.   IF KickVersion(36) THEN CacheClearU()  -> Write out the cache (68040 especially bad...)
  47.   RETURN mem
  48. EXCEPT
  49.   RETURN NIL
  50. ENDPROC
  51.  
  52. start:
  53. function:
  54.   LONG 0
  55. storeA4:
  56.   LONG 0
  57. entry:
  58.   MOVE.L storeA4(PC), A4      -> Restore A4
  59.   MOVE.L function(PC), -(A7)
  60.   RTS                         -> Call real function
  61. end:
  62.   NOP
  63.  
  64. pStart:
  65. pFunction:
  66.   LONG 0
  67. pStoreA4:
  68.   LONG 0
  69. pEntry:
  70.   MOVEM.L D2-D7/A2-A6, -(A7)  -> Preserve registers
  71.   MOVE.L pStoreA4(PC), A4     -> Restore A4
  72.   MOVE.L pFunction(PC), A5
  73.   JSR (A5)                    -> Call real function
  74.   MOVEM.L (A7)+, D2-D7/A2-A6  -> Restore registers
  75.   RTS
  76. pEnd:
  77.   NOP
  78.  
  79. aStart:
  80. aFunction:
  81.   LONG 0
  82. aStoreA4:
  83.   LONG 0
  84. aEntry:
  85.   MOVE.L (A7)+, A1            -> Remember the caller
  86.   MOVE.L (A7), A0             -> Swap 3 arguments
  87.   MOVE.L 8(A7), (A7)
  88.   MOVE.L A0, 8(A7)
  89.   LEA aStack(PC), A0
  90.   MOVEM.L D2-D7/A1-A6, (A0)   -> Preserve registers
  91.   MOVE.L aStoreA4(PC), A4     -> Restore A4
  92.   MOVE.L aFunction(PC), A0
  93.   JSR (A0)                    -> Call real function
  94.   LEA aStack(PC), A0
  95.   MOVEM.L (A0), D2-D7/A1-A6   -> Restore registers
  96.   MOVE.L A1, -(A7)            -> Restore caller
  97.   RTS
  98. aStack:
  99.   LONG 2,3,4,5,6,7,1,2,3,4,5,6,0
  100. aEnd:
  101.   NOP
  102.  
  103. cStart:
  104. cFunction:
  105.   LONG 0
  106. cStoreA4:
  107.   LONG 0
  108. cEntry:
  109.   MOVE.L (A7)+, A1            -> Remember the caller
  110.   MOVE.L (A7), A0             -> Swap 2 arguments
  111.   MOVE.L 4(A7), (A7)
  112.   MOVE.L A0, 4(A7)
  113.   LEA cStack(PC), A0
  114.   MOVEM.L D2-D7/A1-A6, (A0)   -> Preserve registers
  115.   MOVE.L cStoreA4(PC), A4     -> Restore A4
  116.   MOVE.L cFunction(PC), A0
  117.   JSR (A0)                    -> Call real function
  118.   LEA cStack(PC), A0
  119.   MOVEM.L (A0), D2-D7/A1-A6   -> Restore registers
  120.   MOVE.L A1, -(A7)            -> Restore caller
  121.   RTS
  122. cStack:
  123.   LONG 2,3,4,5,6,7,1,2,3,4,5,6,0
  124. cEnd:
  125.   NOP
  126.  
  127. hStart:
  128. hFunction:
  129.   LONG 0
  130. hStoreA4:
  131.   LONG 0
  132. hEntry:
  133.   LEA hStack(PC), A0
  134.   MOVEM.L D2-D7/A2-A4, (A0)  -> Preserve registers
  135.   MOVE.L hStoreA4(PC), A4    -> Restore A4
  136.   MOVE.L hFunction(PC), A0
  137.   MOVEM.L D1/A1, -(A7)       -> Push D1 and A1 as arguments
  138.   JSR (A0)                   -> Call real function
  139.   LEA 8(A7), A7              -> Remove arguments
  140.   LEA hStack(PC), A0
  141.   MOVEM.L (A0), D2-D7/A2-A4  -> Restore registers
  142.   RTS
  143. hStack:
  144.   LONG 2,3,4,5,6,7,2,3,4,0
  145. hEnd:
  146.   NOP
  147.  
  148. sStart:
  149. sFunction:
  150.   LONG 0
  151. sStoreA4:
  152.   LONG 0
  153. sEntry:
  154.   LEA sStack(PC), A6
  155.   MOVEM.L D2-D7/A2-A4, (A6)  -> Preserve registers
  156.   MOVE.L sStoreA4(PC), A4    -> Restore A4
  157.   MOVE.L sFunction(PC), A6
  158.   MOVE.L A1, -(A7)           -> Push A1 as an argument
  159.   JSR (A6)                   -> Call real function
  160.   LEA 4(A7), A7              -> Remove argument
  161.   LEA sStack(PC), A6
  162.   MOVEM.L (A6), D2-D7/A2-A4  -> Restore registers
  163.   MOVE.L #CUSTOMADDR, A0     -> Reset A0 to custom base
  164.   TST.L D0                   -> Set Z flag according to func result
  165.   RTS
  166. sStack:
  167.   LONG 2,3,4,5,6,7,2,3,4,0
  168. sEnd:
  169.   NOP
  170.  
  171. iStart:
  172. iFunction:
  173.   LONG 0
  174. iStoreA4:
  175.   LONG 0
  176. iEntry:
  177.   LEA iStack(PC), A0
  178.   MOVEM.L D2-D7/A2-A4/A6, (A0)  -> Preserve registers
  179.   MOVE.L iStoreA4(PC), A4       -> Restore A4
  180.   MOVE.L iFunction(PC), A0
  181.   MOVE.L A1, -(A7)              -> Push A1 as an argument
  182.   JSR (A0)                      -> Call real function
  183.   LEA 4(A7), A7                 -> Remove argument
  184.   LEA iStack(PC), A0
  185.   MOVEM.L (A0), D2-D7/A2-A4/A6  -> Restore registers
  186.   RTS
  187. iStack:
  188.   LONG 2,3,4,5,6,7,2,3,4,6,0
  189. iEnd:
  190.   NOP
  191.  
  192. oStart:
  193. oFunction:
  194.   LONG 0
  195. oStoreA4:
  196.   LONG 0
  197. oEntry:
  198.   MOVE.L 4(A7), A0             -> Swap 2 arguments
  199.   MOVE.L 8(A7), 4(A7)
  200.   MOVE.L A0, 8(A7)
  201.   MOVE.L oStoreA4(PC), A4      -> Restore A4
  202.   MOVE.L oFunction(PC), -(A7)
  203.   RTS                          -> Call real function
  204. oEnd:
  205.   NOP
  206.  
  207.  
  208.